<!--
* description: 采购计划维护-新增弹窗
-->
<template>
  <section class="editCarBrand">
    <el-dialog
      v-dialogDrag
      :close-on-click-modal="false"
      :title="textMap[popupsState]"
      :append-to-body="true"
      :visible.sync="curPopupsVisible"
      @close="sendCode"
      width="800px"
    >
      <dialogHeader
        slot="title"
        :title="textMap[popupsState]"
        :styleType="$store.state.app.dialogType"
      ></dialogHeader>
      <div class="filter-container filter-params">
        <el-row :gutter="26">
          <component
            v-for="comp in tableComponents.filter(o => o.isMust === true)"
            :ref="comp.isRequire ? comp.isRequire+ comp.compKey : comp.compKey"
            :validrule="comp.validrule"
            :key="comp.compKey"
            :codeField="comp.codeField"
            :textField="comp.textField"
            :popupsKey="comp.compKey"
            :is="comp.component"
            :code="formField[comp.codeField]"
            :text="formField[comp.textField]"
            @changeCode="getComponentCode"
            @focusCode="getFocusCode"
            :disabled="comp.disabled"
            :isRequire="comp.isRequire"
            :span="comp.span || 8"
            :isMul="comp.isMul"
            :labelName="comp.labelName"
            :lookuptype="comp.lookuptype"
            :options="comp.options"
            :dateOptionsType="comp.dateOptionsType"
            :dataToObject="comp.dataToObject"
            :readonly="comp.readonly"
            :placeholder="comp.placeholder"
            :isInput="comp.isInput"
          ></component>
        </el-row>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button
          v-for="comp in tableButtons"
          :key="comp.compKey"
          :type="comp.type"
          @click="comp.clickEvent"
        >{{comp.text}}</el-button>
      </div>
    </el-dialog>
  </section>
</template>
<script>
import { formMixins } from "@/components/wms/mixins/formMixins";
import { wmsApis } from "@/api/wms/baseData/api";
import storage from "@/utils/storage";
import request from "@/utils/request";
export default {
  // 组件混入对象
  mixins: [formMixins],
  components: {
    dialogHeader: () => import("@/components/dialogHeader") //弹窗标题
  },
  watch: {
    popupsVisible(val) {
      if (val) {
        if (
          this.formField.pageId !== "" &&
          this.$route.query.pageId !== undefined &&
          this.$route.query.pageId !== this.formField.pageId
        ) {
          this.formField.pageId = this.$route.query.pageId;
          this.formField.pageName = this.$route.query.pageName;
        }
        this.formField.langLabelName = this.formField.label;
        this.backFormField = JSON.parse(JSON.stringify(this.formField));
        this.querySelect;
      }
    }
  },
  data() {
    return {
      // 保存API配置对象
      apiConfig: wmsApis.savePartList,
      // 动态组件-按钮
      tableButtons: [
        {
          compKey: "btnKey1",
          type: "primary",
          size: "small",
          clickEvent: () => this.save(),
          text: "保存" //"保存"
        },
        {
          compKey: "btnKey2",
          type: "",
          size: "small",
          clickEvent: () => this.reset(),
          text: "重置" //"重置"
        }
      ],
      // 动态组件-查询条件
      tableComponents: [
        {
          compKey: "edit_compKey1",
          labelName: "备件编号",
          span: 12,
          codeField: "PART_NO",
          // isRequire: true,
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true,
          disabled: true
        },
           {
          compKey: "edit_compKey2",
          labelName: "零件编号",
          span: 12,
          codeField: "COMPONENTS_NO",
          // isRequire: true,
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true,
          disabled: true
        },
        {
          compKey: "edit_compKey3",
          labelName: "备件名称",
          span: 12,
          codeField: "PART_NAME",
          // isRequire: true,
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true,
          disabled: true
          
        },
        {
          compKey: "edit_compKey4",
          labelName: "备件英文名称",
          span: 12,
          codeField: "PART_NAME_EN",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isRequire: false,
          isMust: true,
          
          disabled: true,
        },
        {
          compKey: "edit_compKey5",
          labelName: "备件单位",
          span: 12,
          codeField: "UNIT",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true,
             disabled: true
        },
        {
          compKey: "edit_compKey6",
          labelName: "长（mm）",
          span: 12,
          codeField: "LENGTH",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true,
          isInput: true,
             disabled: true,
          changed: val => {
            if (!val) {
              this.formField.PART_CUBAGE = "";
              return;
            }
            if (this.formField.LENGTH < 1) {
              this.$refs["edit_compKey5"][0].modelCode = 1;
              this.formField.LENGTH = 1;
            }
            this.$refs["edit_compKey5"][0].modelCode = (
              this.formField.LENGTH + ""
            )
              .replace(/[^\d^\.]+/g, "")
              .replace(".", "$#$")
              .replace(/\./g, "")
              .replace("$#$", ".");
            this.formField.LENGTH = (this.formField.LENGTH + "")
              .replace(/[^\d^\.]+/g, "")
              .replace(".", "$#$")
              .replace(/\./g, "")
              .replace("$#$", ".");
            this.numInput();
          },
          dataToObject: {
            maxLength: 4
          }
        },
        {
          compKey: "edit_compKey7",
          labelName: "宽（mm）",
          span: 12,
          codeField: "WIDTH",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true,
          isInput: true,
             disabled: true,
          changed: val => {
            if (!val) {
              this.formField.PART_CUBAGE = "";
              return;
            }
            if (this.formField.WIDTH < 1) {
              this.$refs["edit_compKey6"][0].modelCode = 1;
              this.formField.WIDTH = 1;
            }
            this.$refs["edit_compKey6"][0].modelCode = (
              this.formField.WIDTH + ""
            )
              .replace(/[^\d^\.]+/g, "")
              .replace(".", "$#$")
              .replace(/\./g, "")
              .replace("$#$", ".");
            this.formField.WIDTH = (this.formField.WIDTH + "")
              .replace(/[^\d^\.]+/g, "")
              .replace(".", "$#$")
              .replace(/\./g, "")
              .replace("$#$", ".");
            this.numInput();
          },
          dataToObject: {
            maxLength: 4
          }
        },
        {
          compKey: "edit_compKey8",
          labelName: "高（mm）",
          span: 12,
          codeField: "HEIGHT",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true,
             disabled: true,
          isInput: true,
          changed: val => {
            if (!val) {
              this.formField.PART_CUBAGE = "";
              return;
            }
            if (this.formField.HEIGHT < 1) {
              this.$refs["edit_compKey7"][0].modelCode = 1;
              this.formField.HEIGHT = 1;
            }
            this.$refs["edit_compKey7"][0].modelCode = (
              this.formField.HEIGHT + ""
            )
              .replace(/[^\d^\.]+/g, "")
              .replace(".", "$#$")
              .replace(/\./g, "")
              .replace("$#$", ".");
            this.formField.HEIGHT = (this.formField.HEIGHT + "")
              .replace(/[^\d^\.]+/g, "")
              .replace(".", "$#$")
              .replace(/\./g, "")
              .replace("$#$", ".");
            this.numInput();
          },
          dataToObject: {
            maxLength: 4
          }
        },
        {
          compKey: "edit_compKey9",
          labelName: "体积（mm³）",
          span: 12,
          codeField: "PART_CUBAGE",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true,
          readonly: true,
          placeholder: "",
             disabled: true,
          dataToObject: {
            maxWordCount: 8
          }
        },
        {
          compKey: "edit_compKey10  ",
          labelName: "采购SNP",
          span: 12,
          codeField: "SNP_IN",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true,
          isInput: true,
          isRequire: true,
          changed: val => {
            this.$refs["trueedit_compKey9"][0].modelCode = (
              this.formField.SNP_IN + ""
            ).replace(/[^\d]/g, "");
            this.formField.SNP_IN = (this.formField.SNP_IN + "").replace(
              /[^\d]/g,
              ""
            );
          },
          dataToObject: {
            maxLength: 10
          }
        },
        {
          compKey: "edit_compKey18",
          labelName: "销售SNP",
          span: 12,
          codeField: "SNP_OUT",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true,
          isInput: true,
          isRequire: true,
          changed: val => {
            this.$refs["trueedit_compKey18"][0].modelCode = (
              this.formField.SNP_OUT + ""
            ).replace(/[^\d]/g, "");
            this.formField.SNP_OUT = (this.formField.SNP_OUT + "").replace(
              /[^\d]/g,
              ""
            );
          },
          dataToObject: {
            maxLength: 10
          }
        },
        {
          compKey: "edit_compKey19",
          labelName: "调拨SNP",
          span: 12,
          codeField: "SNP_MOVE",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true,
          isInput: true,
          isRequire: true,
          changed: val => {
            this.$refs["trueedit_compKey19"][0].modelCode = (
              this.formField.SNP_MOVE + ""
            ).replace(/[^\d]/g, "");
            this.formField.SNP_MOVE = (this.formField.SNP_MOVE + "").replace(
              /[^\d]/g,
              ""
            );
          },
          dataToObject: {
            maxLength: 10
          }
        },
        {
          compKey: "edit_compKey10",
          labelName: "计费重量",
          span: 12,
          codeField: "CHARGED_WEIGHT",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true,
          isInput: true,
             disabled: true,
          changed: val => {
            this.$refs["edit_compKey10"][0].modelCode = (
              this.formField.CHARGED_WEIGHT + ""
            )
              .replace(/[^\d^\.]+/g, "")
              .replace(".", "$#$")
              .replace(/\./g, "")
              .replace("$#$", ".");
            this.formField.CHARGED_WEIGHT = (this.formField.CHARGED_WEIGHT + "")
              .replace(/[^\d^\.]+/g, "")
              .replace(".", "$#$")
              .replace(/\./g, "")
              .replace("$#$", ".");
          },
          dataToObject: {
            maxLength: 10
          }
        },
        {
          compKey: "edit_compKey11",
          labelName: "包装类型",
          codeField: "BALE_TYPE",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "dropdownList",
          isMust: true,
          span: 12,
          // isRequire: true,
             disabled: true,
          isMul: false,
          options: []
        },
        {
          compKey: "12",
          labelName: "摩擦系数",
          span: 12,
          codeField: "COF",
          component: () => import("@/components/wms/commonInput"),
          type: "inputText",
          isMust: true,
          isInput: true,
          changed: val => {
            this.$refs["12"][0].modelCode = (
              this.formField.COF + ""
            )
              .replace(/[^\d^\.]+/g, "")
              .replace(".", "$#$")
              .replace(/\./g, "")
              .replace("$#$", ".");
            this.formField.COF = (this.formField.COF + "")
              .replace(/[^\d^\.]+/g, "")
              .replace(".", "$#$")
              .replace(/\./g, "")
              .replace("$#$", ".");
          },
          dataToObject: {
            maxLength: 10
          }
        },
        {
          compKey: "edit_compKey13",
          labelName: "供应商",
          textField: "PARTNER_SHORT_NAME",
          codeField: "SUPPLIER_CODE",
          component: () =>
            import("@/components/wms/wmsEjectWindows/wmsSupplier"),
          type: "propus",
          isMust: true,
          span: 23,
          isMul: false,
          // isRequire: true,
            disabled: true,
          readonly: true,
          returnCodeField: "SUPPLIER_CODE",
          returnTextField: "PARTNER_SHORT_NAME"
        },
        {
          compKey: "edit_compKey14",
          labelName: "备件属性",
          codeField: "PART_ATTR",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "dropdownList",
          span: 23,
          isMust: true,
          isMul: false,
          // isRequire: true,
             disabled: true,
          options: [
           
          ]
        },
        {
          compKey: "edit_compKey15",
          labelName: "追溯件标识",
          codeField: "IS_RETROSPECT",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "dropdownList",
          span: 23,
          isMust: true,
          isMul: false,
          // isRequire: true,
          options: [
            {
              label: "是",
              value: "1"
            },
            {
              label: "否",
              value: "0"
            }
          ]
        },
        {
          compKey: "edit_compKey16",
          labelName: "自制件标识",
          codeField: "IS_HOMEMADE",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "dropdownList",
          span: 23,
          isMust: true,
          isMul: false,
          // isRequire: true,
          disabled: true,
          options: [
            {
              label: "是",
              value: "1"
            },
            {
              label: "否",
              value: "0"
            }
          ]
        },
        
        {
          compKey: "edit_compKey17",
          labelName: "所属中心库",
          textField: "WAREHOUSE_NAME",
          codeField: "WAREHOUSE_ID",
          component: () =>
            import("@/components/wms/wmsEjectWindows/wmsWarehouse/indexC"),
          type: "propus",
          isMust: true,
          span: 23,
          isMul: false,
          readonly: false,
          returnCodeField: "WAREHOUSE_ID",
          returnTextField: "WAREHOUSE_NAME",
          // isRequire: true
        },
          {
          compKey: "edit_compKey18",
          labelName: "状态",
          codeField: "IS_ENABLE",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "dropdownList",
          span: 23,
          isMust: true,
          isMul: false,
          disabled: true,
          // isRequire: true,
          options: [
            {
              label: "启用",
              value: "1"
            },
            {
              label: "禁用",
              value: "0"
            }
          ]
        },
           {
          compKey: "edit_compKey19",
          labelName: "一键代发",
          codeField: "IS_AUTO",
          component: () => import("@/components/wms/dropdownList/dropdownList"),
          type: "dropdownList",
          span: 23,
          isMust: true,
             disabled: true,
          isMul: false,
          // isRequire: true,
          options: [
            {
              label: "是",
              value: "1"
            },
            {
              label: "否",
              value: "0"
            }
          ]
        },
        {
          compKey: "edit_compKey20",
          labelName: "计划员",
          textField: "PLAN_USER",
          codeField: "PLAN_USER",
          component: () =>
            import("@/components/wms/wmsEjectWindows/wmsWarehouse"),
          type: "propus",
          isMust: true,
          span: 23,
          isMul: false,
          disabled: true,
          readonly: false,
          returnCodeField: "PLAN_USER",
          returnTextField: "PLAN_USER",
          // isRequire: true
        },
      ],
      // 标题
      textMap: {
        edit: "采购计划维护信息",
        add: "新增备件信息"
      },
      // 表单数据（无需赋值，由混入对象赋值）
      formField: {
        // 备件编号
        PART_NO: "", 
        // 零件编号
        COMPONENTS_NO:"",
        // 备件名称
        PART_NAME: "",
        // 备件英文名称
        PART_NAME_EN: "",
        // 单位
        UNIT: "",
        // 长
        LENGTH: "",
        // 宽
        WIDTH: "",
        // 高
        HEIGHT: "",
        // 体积
        PART_CUBAGE: "",
        // SNP
        SNP_IN: "",
        SNP_OUT: "",
        SNP_MOVE: "",
        // 计费重量
        CHARGED_WEIGHT: "",
        // 包装类型
        BALE_TYPE: "",
        // 摩擦系数
        COF: "",
        // 供应商
        SUPPLIER_CODE: "",
        PARTNER_SHORT_NAME: "",
        // 备件属性
        PART_ATTR: "",
        // 追溯件标识
        IS_RETROSPECT: "1",
        // 自制件标识
        IS_HOMEMADE: "1",
        // 状态
        IS_ENABLE:"",
        // 所属中心库
        WAREHOUSE_NAME: "",
        // 组件ID
        PART_ID: "",
        //计划员
        PLAN_USER:"",
        // 一键代发
        IS_AUTO:""

      }
    };
  },
  methods: {
    numInput() {
      this.formField.PART_CUBAGE =
        (this.formField.LENGTH - 0) *
        (this.formField.WIDTH - 0) *
        (this.formField.HEIGHT - 0);
    },
    onCreated() {
      if (this.curPopupsVisible) {
          this.tableComponents[13].options = []
        request({
          url: "/mp/wm/vl/basedata/boxcommon/queryBaleTypeBox.do",
          method: "post",
          data: {}
        }).then(res => {
          res.listRow.map(item => {
            this.tableComponents[13].options.push({
              label: item.BALE_TYPE_NAME,
              value: item.BALE_TYPE
            });
          });
        });
        // 所属中心库接口
        //  this.tableComponents[18].options = []
         request({
        url: "/mp/wm/vl/basedata/partlist/queryWarehouse.do",
        method: "post",
        data: {}
      }).then(res => {
         if (res.listRow && res.listRow.length > 0){
          res.listRow.map(item => {
            this.tableComponents[20].options.push({
              label: item.WAREHOUSE_NAME,
              value: item.WAREHOUSE_ID
            });
          });
        }
      });

       this.tableComponents[16].options = []
        request({
          url: "/mp/wm/vl/basedata/boxcommon/queryPartAttrBox.do",
          method: "post",
          data: {}
        }).then(res => {
          res.listRow.map(item => {
          
            this.tableComponents[16].options.push({
              label: item.PART_ATTR_NAME,
              value: item.PART_ATTR
            });
          });
        });
      }
    },
    //保存
    save() {
      this.$utils.validataMoth(this, "validpopup");
      if (this.valid) {
        var saveObj = JSON.parse(JSON.stringify(this.formField));
        //保存表单
        this.saveForm(saveObj);
        storage.remove(this.$route.query.pageCode);
      }
    }
  }
};
</script>
